<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="../../layouts/App/reset.css" />
    <link rel="stylesheet" href="./og-image.css" />
  </head>

  <body>
    <main class="container">
      <header class="header">
        <div class="divider"></div>
        <span class="date"></span>
      </header>
      <h1 class="title"></h1>
      <footer class="footer">
        <div class="author">
          <img class="avatar" src="../../../public/static/avatar.jpg" alt="Hamish" />
          <span>Hamish Williams</span>
        </div>
        <div class="timecode"></div>
      </footer>
    </main>
    <script>
      const container = document.querySelector('.container');
      const title = document.querySelector('.title');
      const date = document.querySelector('.date');
      const timecode = document.querySelector('.timecode');

      const params = new URLSearchParams(window.location.search);
      const postDate = new Date(params.get('date') || '2022-01-01');
      const defaultBanner = '/static/og-blank.png';
      const bannerImage = params.get('banner') || defaultBanner;

      container.style.setProperty('--url', `url('../../../public${bannerImage}')`);
      title.textContent = params.get('title') || 'Untitled';
      timecode.textContent = params.get('timecode') || '00:00:00:00';
      date.textContent = postDate.toLocaleDateString('default', {
        year: 'numeric',
        month: 'long',
        day: '2-digit',
      });
    </script>
  </body>
</html>
